<?php

namespace fanletter\library;

/**
 * 
 * Secure PDO Class to surpress all the Exceptions
 * @author Evan
 *
 */
Class PDOSafe extends \PDO {

	public static function exception_handler($exception) 
	{
		// Ausgabe der Exception-Details
		die('Uncaught exception: '. $exception->getMessage());
	}
 
	/**
	 * 
	 * @param String $dsn
	 * @param String $username
	 * @param String $password
	 * @param Array $driver_options
	 * 
	 * @return PDOSafe
	 */
	public function __construct($dsn = '', $username='', $password='', Array $driver_options = array()) 
	{
		$dsn = (String) $dsn;
		$username = (String) $username;
		$password = (String) $password;

		// Kurz den Handler ändern
		set_exception_handler(array(__CLASS__, 'exception_handler'));

		// PDO Objekt instanziieren
		parent::__construct($dsn, $username, $password, $driver_options);

		// Und wieder zurücksetzen
		restore_exception_handler();
	}
	
}
